package com.medical.device.controller;


import com.medical.device.Application;
import com.medical.device.common.R;
import com.medical.device.entity.Test;
import com.medical.device.service.ITestService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yy
 * @since 2020-02-20
 */

@Api(tags = "测试模块")
@RestController
@RequestMapping("/test")
public class TestController {

    private static final Logger logger = LoggerFactory.getLogger(Application.class);

    @Autowired
    ITestService iTestService;

    @ApiOperation(value = "获取用户信息", response = Test.class)
    @GetMapping("/{id}")
    public ResponseEntity getUser(@PathVariable("id") Integer id) {
        Test test;

        try {
            test = iTestService.getById(id);
            if (test==null) {
                return new ResponseEntity(R.error("没有数据"), HttpStatus.NOT_FOUND);
            }
            return ResponseEntity.ok(R.success(test));
        } catch (Exception e) {
            logger.error(e.getMessage());
            return new ResponseEntity(R.error(), HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }
}

